import { DynamicModule, Global, Module } from '@nestjs/common';
import { WechatService } from './wechat.service';
import { HttpModule } from '@nestjs/axios';
import { WechatConfig } from './type/WechatConfig';

@Global()
@Module({
    imports : [HttpModule]
})
export class WechatModule {
	static forRootAsync(options: {
		imports?: any[];
		useFactory: (...args: any[]) => Promise<WechatConfig> | WechatConfig;
		inject?: any[];
	  }): DynamicModule {
		const providers = [
		  {
			provide: 'WECHAT_CONFIG',
			useFactory: options.useFactory,
			inject: options.inject || [],
		  },
		  WechatService,
		];
	
		return {
		  module: WechatModule,
		  providers: providers,
		  exports: [WechatService],
		};
	}
}
